package
{
	public class WordToSvr
	{
		
		import mx.collections.ArrayCollection;
		import mx.rpc.http.mxml.HTTPService;
		import flash.net.*;
		
		private var exXml:XML;
		private var wc:ArrayCollection;
		private var wl:WordLocation;
		private var docName:String;			
		private	var docNum:int;
		public var addStr:String;

		public function WordToSvr(name:String, num:int, ac:ArrayCollection){
			this.wc = ac;
			this.docName = name;
			this.docNum = num;
		}		
		
		public function wordSend():void{
						
												
			addStr = "<text>";
			var count:int;
				
				
			for(var i:int = 0; i<wc.length; i++){
				wl = (WordLocation)(wc.getItemAt(i));
				//wl.name = "a"+i+" ";
				
				addStr += "<word_info>";
				addStr += "<name>"+wl.name+"</name>";
				addStr += "<eng>"+wl.eng+"</eng>";
				count = 0;
				for(var j:int = 0; j<wl.getSize(); j++){
					count++;
					addStr += "<word>";
					addStr += "<sp>"+(int)(wl.sp.getItemAt(j))+"</sp>";
					addStr += "<ep>"+(int)(wl.ep.getItemAt(j))+"</ep>";
					addStr += "<color>"+(uint)(wl.color.getItemAt(j))+"</color>";
					addStr += "</word>";
					
				}
				addStr += "<count>"+count+"</count>";
				addStr += "</word_info>";
			}
			
			addStr += "</text>";
			
			exXml = new XML(addStr);
			
					
		
			wordInfoToSvr();
		}
		
		private function wordInfoToSvr():void {
	    	var sendVars:URLVariables = new URLVariables();
	    	sendVars.action = "upload";
	    	sendVars.name = docName+docNum;
	    	sendVars.text = exXml.toXMLString();
	    		
	    	var request:URLRequest = new URLRequest("http://localhost:80/xmlup.php");
	    	request.data = sendVars;
	    	
	    	//request.contentType = "text/xml";	    		
			
			request.method = URLRequestMethod.POST;
				
			var loader:URLLoader = new URLLoader();
			//loader.addEventListener(Event.COMPLETE, completeHandler);
			//loader.addEventListener(Event., feHandler);
			
			loader.load(request);
		}
		

	}
}